package com.pine.dbant.common.plugin;

import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.Map;

/**
 * @author xiaoyuan
 * @create 2022/11/7 14:46
 **/
@Setter
@Getter
public class QueryExecuteRecord extends ExecuteRecord {


    /**
     * 字段
     */
    private List<Column> columns;

    /**
     * 数据
     */
    private List<Map<String, Object>> rows;

    /**
     * 总条数
     */
    private Long total = 0L;

    /**
     * 当前页码
     */
    private Integer pageIndex = 0;

    /**
     * 分页码数
     */
    private Integer pageSize = 10;

    /**
     * 编辑权限
     */
    private boolean editAuth = false;

    /**
     * 表名称
     */
    private String tableName;

    /**
     * 是否进行分页查询：分页将返回更少的数据
     */
    private boolean noPage = false;

    /**
     * 计算总页码
     * @return
     */
    public long getPageCount() {
        if (this.getPageSize() == 0L) {
            return 0L;
        } else {
            long pages = this.getTotal() / this.getPageSize();
            if (this.getTotal() % this.getPageSize() != 0L) {
                ++pages;
            }

            return pages;
        }
    }

}
